// pages/user/user/userPutInData/userPutInData.js
const app = getApp();
import Api from '../../../../utils/http';
var wxCharts = require('../../../../utils/wxcharts.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pointDetails: null,
    listHis: [],
    userInfo: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      options: options
    });
    that.getusertext();
      that.getData();
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  //cavns数据
  canvas: function () {
    var that = this;
    //分类
    let pointDetails = that.data.pointDetails;
    var title = [];
    var weights = [];
    for (var i in pointDetails) {
      var obj = {
        title: pointDetails[i].title,
        weights: pointDetails[i].weight
      }
      title = title.concat(obj.title);
      //console.log(title);
      weights = weights.concat(obj.weights);
      // console.log(weights);
    }
    that.setData({
      title: title,
      weights: weights,
    });
    //分类信息
    new wxCharts({
      canvasId: 'lineCanvas',
      type: 'column',
      categories: title,
      series: [{
        name: '综合纸',
        data: weights,
        format: function (val, name) {
          return val + 'kg';
        }
      }],
      yAxis: {
        min: 0,
      },
      extra: {
        column: {
          width: 25
        }
      },
      width: 400,
      height: 300,

      dataLabel: true,
      legend: false,
    });
  },
  //个人信息详情
  getusertext: function () {
    console.log(this.data)
    var that = this;
    let uid = wx.getStorageSync('userid');
    var param = {
      uid: uid.id,
      user_type: uid.user_type,
    };
    console.log(param)
    Api.ajax("/app/Zpersonalcenter/userInfo", param).then(res => {
      console.log(res)
      if (res.code == 200) {
        that.setData({
          userInfo: res.data,
        })
      }
    })
  },
  //用户调取投放点详情数据
  getData: function () {
    var that = this;
    let uid = wx.getStorageSync('userid')
    var param = {
      selType: 1,
      type: 2,
      uid: uid.id,
      user_type:uid.user_type,
    };
    console.log(param)
    Api.ajax("/app/Zmanage/dataForm", param).then(res => {
      console.log(res)
      if (res.code == 200) {
        that.setData({
          pointDetails: res.data
        })

        that.canvas();

      }
    });
  },
  
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})